package CardLayoutTest;

import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.CardLayout;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class Main extends JFrame implements ActionListener{

 
  private Button [] barray;
  private Container con;
  private CardLayout cl;
  private JPanel pp;

  Main(){

   cl = new CardLayout();
   con = this.getContentPane();
   con.setLayout(new BorderLayout());
   this.setBounds(600, 200, 600, 600);

   barray = new Button[4];

   init();
  }

  private void init(){

   JPanel bp = new JPanel();
   pp = new JPanel();
   pp.setLayout(cl);
   bp.setLayout(new GridLayout(1,4));

   pp.add(new PaintImg("Images\\title.gif"),"card1");
   pp.add(new PaintImg("images\\yutpan.gif"),"card2");
   pp.add(new PaintImg("img\\img3.png"),"card3");
   pp.add(new PaintImg("img\\img4.jpg"),"card4");

   String []btstr = {"사진변경1","사진변경2","사진변경3","사진변경4"};

   for(int i = 0; i < barray.length; i++){ //버튼 초기화

    barray[i] = new Button(btstr[i]);
    barray[i].setPreferredSize(new Dimension(0,40));
    barray[i].addActionListener(this);
    bp.add(barray[i]);

   }

   con.add(pp,"Center");
   con.add(bp,"South");
   this.setVisible(true);

  }

  public static void main(String[] args) {
	  
    new Main();
  }

  @Override

  public void actionPerformed(ActionEvent e) {
	  
   switch(e.getActionCommand()){

   case "사진변경1" :cl.show(pp, "card1");break; 
   case "사진변경2" :cl.show(pp, "card2");break; 
   case "사진변경3" :cl.show(pp, "card3");break; 
   case "사진변경4" :cl.show(pp, "card4");break; 

   }

  }

}




